package com.yenlien.traceyun.business.controller;

import com.yenlien.traceyun.business.bean.Search;
import com.yenlien.traceyun.business.dao.WarehouseDao;
import com.yenlien.traceyun.business.dao.WarehousePartDao;
import com.yenlien.traceyun.business.entity.StorageManage;
import com.yenlien.traceyun.business.service.WarehouseService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-12-22
 * @description:
 **/

@RestController
@RequestMapping(value = "/warehouse")
public class WarehouseController extends BaseController {

    @Autowired
    private WarehouseService warehouseService;

    @Autowired
    private WarehouseDao warehouseDao;

    @Autowired
    private WarehousePartDao warehousePartDao;

    @PostMapping(value = "/part/detail")
    public Object partDetail(@RequestBody Search search) {
        return warehouseService.pageDetail(search);
    }

    @GetMapping(value = "/list")
    public Object listWarehouse() {
        Sort sort = Sort.by(Sort.Direction.DESC, "createtime");
        return success(warehouseDao.findAll(sort));
    }

    @GetMapping(value = "/listpart/{warehouseId}")
    public Object listpart(@PathVariable("warehouseId") String warehouseId) {
        return success(warehousePartDao.findByWarehouseId(warehouseId));
    }

    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    public Object tree() {
        return warehouseService.trees();
    }

    @GetMapping(value = "/partdele/{partid}")
    public Object partDele(@PathVariable("partid") String partid) {
        warehousePartDao.deleteById(partid);
        return success("ok");
    }

}
